<?php
declare (strict_types=1);

namespace app\course\logic\record\admin;

use app\course\logic\base\Course;
use app\course\model\base\CourseSection;
use app\course\model\classes\admin\ClassesLink;
use app\course\model\record\admin\LearnCourseFinished as LearnCourseFinishedModel;
use app\user\logic\user\admin\Account;

/**
 * 课程学完的学员逻辑类
 */
class LearnCourseFinished extends LearnCourseFinishedModel
{

    // /**
    //  * 已经学完的学员列表
    //  * Author   Martinsun<syh@sunyonghong.com>
    //  * Date 2020-08-07
    //  *
    //  * @param array $map [description]
    //  * @return   [type]                              [description]
    //  */
    // public function getStudentList(array $map = [], int $course_id, $phone = null)
    // {
    //     $builder = $this->with(['user']);
    //     if ($phone) {
    //         $user_id = Account::withTrashed()->where('phone', $phone)->value('id');
    //
    //         $builder = $builder->where('user_id', $user_id);
    //     }
    //     return $builder->where('course_id', $course_id)->where($map)->paginate($this->getListRows());
    // }

    /**
     * 已经学完的课程列表
     * Author   Martinsun<syh@sunyonghong.com>
     * Date 2020-08-07
     *
     * @param array $map [description]
     * @return   [type]                              [description]
     */
    public function getCourseList(array $map = [], int $user_id)
    {
        return $this->withJoin(['course' => ['title']])->where('__TABLE__.user_id', $user_id)->where($map)->paginate($this->getListRows());
    }
}
